package com.beerandjesus.sportofkings.handicapper.factory.profile;

import com.beerandjesus.sportofkings.handicapper.factory.profile.AnalysisProfileResolver;
import com.beerandjesus.sportofkings.handicapper.model.AnalysisProfileType;
import com.beerandjesus.sportofkings.handicapper.model.RaceType;
import com.beerandjesus.sportofkings.handicapper.model.AnalysisProfile;
import com.beerandjesus.sportofkings.handicapper.model.brisnet.singlefile.PastPerformance;
import com.beerandjesus.sportofkings.handicapper.model.brisnet.singlefile.Horse;
import com.beerandjesus.sportofkings.handicapper.model.brisnet.singlefile.HorseRace;

import java.util.List;

/**
 * Date: Jul 6, 2012
 * Time: 2:36:28 PM
 */
public class ClassDropAnalysisProfileResolver implements AnalysisProfileResolver {
    public AnalysisProfile resolve(HorseRace race, Horse horse) {
        RaceType todaysRace = race.getRace().getType();
        List<PastPerformance> pps = horse.getPastPerformances();
        if (pps != null && pps.size() > 0) {
            PastPerformance lastRace = pps.get(0);
            if (lastRace != null) {
                Integer claimingPrice = null;
                try {
                    claimingPrice = Integer.valueOf(race.getRace().getClaimingPrice());
                } catch (NumberFormatException e) {
                    // Ignore
                }
                Integer lastRaceClaimingPrice = null;
                try {
                    lastRaceClaimingPrice = Integer.valueOf(lastRace.getClaimingPrice());
                } catch (NumberFormatException e) {
                    // Ignore
                }
                if (todaysRace.isCramerClassDrop(claimingPrice, lastRace.getRaceType(), lastRaceClaimingPrice)) {
                    return AnalysisProfile.getAnalysisProfile(AnalysisProfileType.DROP_IN_CLASS, 0);
                }
            }
        }
        return null;
    }
}
